//
//  HotAskView.m
//  SHHCPhone
//
//  Created by Sheng long on 14-9-21.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "HotAskView.h"
#import "HotAskViewController.h"

@interface HotAskView()
{
    HotAskTableView *_mainTable;
    
    //关键字填写
    UITextField *_searchField;
    
    //搜索按钮
    UIButton *_searchButton;
    
    //
    UIView *headView;
}
@end

@implementation HotAskView

@synthesize mainTable=_mainTable;
@synthesize askVc,searchField=_searchField;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _mainTable = [[HotAskTableView alloc] initWithFrame:self.bounds];
        [_mainTable setCurrentRefreshType:ALL_REFRESH_STATE];
        [_mainTable setAskView:self];
        [_mainTable setGetDataNumber:IOS_GET_NUMBER];
        [self addSubview:_mainTable];
    }
    return self;
}

//获取headview
-(UIView*)getHeadView
{
    if (!headView) {
        headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 102)];
        [headView setBackgroundColor:GET_COLOR(@"#f7f7f7")];
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, headView.frame.size.width-15*2, 35)];
        [bgView setBackgroundColor:[UIColor whiteColor]];
        [bgView.layer setBorderColor:GET_COLOR(@"#ededed").CGColor];
        [bgView.layer setBorderWidth:1];
        [bgView.layer setCornerRadius:4];
        [headView addSubview:bgView];
        
        _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searchButton setFrame:CGRectMake(bgView.frame.size.width-40, 0, 40, bgView.frame.size.height)];
        [_searchButton setImage:[UIImage imageNamed:@"搜索放大镜icon.png"] forState:UIControlStateNormal];
        [_searchButton setImage:[UIImage imageNamed:@"搜索放大镜icon-点击.png"] forState:UIControlStateHighlighted];
        [bgView addSubview:_searchButton];
        [_searchButton addTarget:self action:@selector(searchButt:) forControlEvents:UIControlEventTouchUpInside];
        
        _searchField = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, _searchButton.frame.origin.x-10, bgView.frame.size.height)];
        [bgView addSubview:_searchField];
        [_searchField setDelegate:askVc];
        [_searchField addTarget:self action:@selector(searchButt:) forControlEvents:UIControlEventEditingDidEndOnExit];
        [_searchField setReturnKeyType:UIReturnKeyDone];
        [_searchField setPlaceholder:@"搜索热门问题"];
        [bgView addSubview:_searchField];
        
        UIButton *button1 = [OftenMenthod setButtonTitle:@"我要提问"];
        [headView addSubview:button1];
        [button1 addTarget:self action:@selector(askButt) forControlEvents:UIControlEventTouchUpInside];
        [button1 setCenter:CGPointMake(headView.frame.size.width/2, button1.frame.size.height/2+CGRectGetMaxY(bgView.frame)+5)];
    }
    return headView;
}

-(void)askButt
{
    [self.askVc pushAskVc];
}

-(void)searchButt:(NSObject*)o
{
    if ([o isKindOfClass:[UIButton class]]) {
        NSString *text = [_searchField.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if (text.length == 0) {
            [LoadingFrameView autoDisappearBlockingview:@"请输入您要搜索的内容"];
        }else{
            [self.askVc searchText];
        }
    }
}

@end
